import { UserInfo } from './socket';

// 文档冲突类型
export interface DocumentConflict {
  nodeId: string;
  localContent: any;
  remoteContent: any;
  remoteUser: UserInfo;
  timestamp: number;
  resolved?: boolean;
}

// 文档版本类型
export interface DocumentVersion {
  id: string;
  content: any;
  version: number;
  createdAt: string;
  createdBy: UserInfo;
  message?: string;
}

// 文档权限类型
export enum DocumentPermission {
  OWNER = 'owner',
  EDITOR = 'editor',
  COMMENTER = 'commenter',
  VIEWER = 'viewer'
}

// 文档节点类型
export interface DocumentNode {
  id: string;
  type: string;
  content: any;
  children?: DocumentNode[];
  attributes?: Record<string, any>;
}

// 文档类型
export interface Document {
  id: string;
  title: string;
  content: any;
  version: number;
  createdAt: string;
  updatedAt: string;
  createdBy: UserInfo;
  updatedBy: UserInfo;
  permissions: Record<string, DocumentPermission>;
}

// 文档操作类型
export type DocumentOperation = 
  | { type: 'insert'; path: number[]; node: DocumentNode }
  | { type: 'delete'; path: number[] }
  | { type: 'update'; path: number[]; properties: Record<string, any> }
  | { type: 'move'; path: number[]; newPath: number[] };

// 文档差异类型
export interface DocumentDiff {
  operations: DocumentOperation[];
  version: number;
  timestamp: number;
  author: UserInfo;
}

// 文档合并结果类型
export interface MergeResult {
  content: any;
  conflicts: DocumentConflict[];
  success: boolean;
  message?: string;
}

// 文档评论类型
export interface DocumentComment {
  id: string;
  content: string;
  author: UserInfo;
  createdAt: string;
  nodeId: string; // 关联的节点ID
  resolved: boolean;
  resolvedBy?: UserInfo;
  resolvedAt?: string;
  replies: DocumentCommentReply[];
}

export interface DocumentCommentReply {
  id: string;
  content: string;
  author: UserInfo;
  createdAt: string;
}

// 文档修订历史记录
export interface DocumentHistory {
  revisions: DocumentVersion[];
  currentVersion: number;
}

// 文档协作状态
export interface DocumentCollaborationState {
  activeUsers: UserInfo[];
  lockedNodes: Record<string, UserInfo>;
  userCursors: Record<string, { position: any; color: string }>;
  conflicts: DocumentConflict[];
} 